package com.sgy.util;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedInputStream;
import java.io.InputStream;

public class StreamUtil {
    public static StringBuffer getRequestBody(HttpServletRequest req) {
        StringBuffer postDataBuff = new StringBuffer();
        try {
            req.setCharacterEncoding("utf-8");
            InputStream in;
            in = req.getInputStream();

            BufferedInputStream buf = new BufferedInputStream(in);
            byte[] buffer = new byte[1024 * 72];
            int iRead;
            while ((iRead = buf.read(buffer)) != -1) {
                postDataBuff.append(new String(buffer, 0, iRead, "UTF-8"));
            }
            in.close();
            buf.close();
        } catch (Exception e) {
            postDataBuff = null;
            e.printStackTrace();
        }
        return postDataBuff;
    }
}
